#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e5+10;
ll n,ans;
ll a[MAXN],b[MAXN];
ll check()
{
    ll num=0;
    for(int i=2;i<=n;i++)
    {
        int j=i-1;
        while(j>0&&b[i]!=b[j]) j--;
        if(j&&a[i]==a[j]) num+=a[i];
    }
    return num;
}
void dfs(ll step)
{
    if(step>n)
    {
        ll p=check();
        if(p>ans) ans=p;
        //cout<<"ok"<<endl;
        return ;
    }

    b[step]=0;
    dfs(step+1);
    b[step]=1;
    dfs(step+1);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--)
    {
        ans=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }

        dfs(1);

        printf("%lld\n",ans);
    }
    return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4
*/
